package com.yand.serviceimpl.business.business;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yand.api.entity.business.product.THfProductDetail;
import com.yand.api.service.business.ProductService;
import com.yand.mapper.business.product.THfProductDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 产品明细相关service实现类
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private THfProductDetailMapper productDetailMapper;


    /**
     * 产品明细
     * @param productDetail
     * @return
     */
    @Override
    public PageInfo<THfProductDetail> queryAllProductList(THfProductDetail productDetail) {

        PageHelper.startPage(productDetail.getPageNum(), productDetail.getPageSize());

        return PageInfo.of(productDetailMapper.selectAllProductList(productDetail));
    }

    /**
     * 获取单个产品的明细
     * @param productDetail
     * @return
     */
    @Override
    public THfProductDetail queryProduct(THfProductDetail productDetail) {
        return productDetailMapper.selectProduct(productDetail);
    }

    /**
     * 根据等级与订单类型获取定价
     * @param level
     * @param orderType
     * @return
     */
    @Override
    public THfProductDetail queryProductPrice(String level, String orderType) {
        THfProductDetail detail = new THfProductDetail();
        detail.setLevel(level);
        THfProductDetail detail1 = queryProduct(detail);
        Integer price = getPriceByType(detail1, Integer.parseInt(orderType));
        detail.setPrice(price);
        return detail;
    }


    /**
     * 通过订单类型获取价格
     * @param detail1
     * @param type
     * @return
     */
    private Integer getPriceByType( THfProductDetail detail1 ,int type){
        Integer price = 0;
        switch (type){
            case 1 :
                price = detail1.getBestCourse();
                break;
            case 2 :
                price = detail1.getOneToOne();
                break;
            case 3 :
                price = detail1.getOneToTwo();
                break;
            case 4 :
                price = detail1.getThreeToSix();
                break;
            case 5 :
                price = detail1.getSevenToMax();
                break;

        }
        return price;

    }


}
